<form id="AddTemplateIdenForm" lay-filter="addGroupForm" class="layui-form model-form ">
    <div class="layui-form-item">
        <label class="layui-form-label">目录名称</label>
        <div class="layui-input-block">
            <input name="name" placeholder="请输入目录名称" type="text" class="layui-input" maxlength="20"
                   lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上级目录</label>
        <div class="layui-input-block">
            <input id="parent_id" name="menuName" placeholder="请输入上级目录" type="text" class="layui-input" maxlength="20"
                   lay-verType="tips" lay-verify="required" disabled/>
        </div>
    </div>
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">选择上级目录</label>-->
<!--        <div class="layui-input-block">-->
<!--            <div id="menuTree"></div>-->
<!--        </div>-->
<!--    </div>-->
    <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary layui-btn-sm" type="button" ew-event="closePageDialog">取消</button>
        <button class="layui-btn layui-btn-sm" lay-filter="addIndexValueMenu" lay-submit >确定</button>
    </div>
</form>
<script>

    layui.use(['layer', 'form', 'admin','tree'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var tree = layui.tree;
        var Authorization;
        var urlData = window.mSelUser;  // 列表页面传递的数据，也可以使用top.xxx
        var userInfo = getAuthority();
        //获取权限方法
        if(userInfo){
            var access_token = localStorage.getExpire("access_token");
            var token_type = localStorage.getExpire("token_type");
            Authorization = token_type+" "+access_token;
        }
        // 表单提交事件
        form.val('addGroupForm', urlData);  // 回显数据
        form.on('submit(addIndexValueMenu)', function (data) {
            var formData = new FormData();
            formData.append('name',data.field.name);
            formData.append('parent_id',urlData.parent_id);
            axios({
                method: 'post',
                data:formData,
                url:microUrl.microObject.microMenu.addMicroMenu,
                headers:{
                    'Authorization':Authorization
                }
            })
                .then(function (res) {
                    if (res.status == 200&&res.data.message=="success") {
                        layer.closeAll('loading');
                        layer.msg("新增成功", {icon: 1});
                    } else {
                        layer.msg(res.data.message, {icon: 2});
                        layer.closeAll('loading');

                    }
                    admin.closeDialog('#AddTemplateIdenForm');
                })
                .catch(function (error) {
                    console.log(error);
                    if(error.response.status === 401 || error.response.status === 403 || error.response.status === 406){
                        // 进行重新登陆
                        localStorage.clear();
                        top.location.href=loginPageUrl;
                    }
                })
            return false;

        });

    });
</script>